﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSC.Portal.Entities;
using System.Web.Mvc;

namespace JSC.Portal.Web.Helper
{
    //public static class ViewContextExtensions
    //{
    //    public static PortalUser CurrentUser(this ViewContext viewContext)
    //    {
    //        return viewContext.HttpContext.User.Identity as PortalUser;
    //    }

    //    public static bool CurrentUserIsInRole(this ViewContext viewContext, params Roles[] roles)
    //    {
    //        PortalUser u = CurrentUser(viewContext);
    //        return (u != null) ? u.IsInRole(roles) : false;
    //    }
    //}

    public static class ControllerContextExtensions
    {
        public static PortalUser CurrentUser(this ControllerContext controllerContext)
        {
            return controllerContext.HttpContext.User.Identity as PortalUser;
        }

        public static bool CurrentUserIsInRole(this ControllerContext controllerContext, params Roles[] roles)
        {
            PortalUser u = CurrentUser(controllerContext);
            return (u != null) ? u.IsInRole(roles) : false;
        }

        public static bool CurrentUserEditAllowed(this ControllerContext controllerContext, Section section)
        {
            PortalUser u = CurrentUser(controllerContext);
            return (u != null) ? u.EditAllowed(section) : false;
        }
    }
}
